package busuanzi.util;

import com.google.common.base.Preconditions;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Auth: bruce-sha
 * Date: 2015/4/29
 */
public abstract class Asserts {

    public static boolean notNull(Object o) {
        try {
            Preconditions.checkNotNull(o);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

//    public static boolean length(String o) {
//        try {
//            Preconditions.checkNotNull(o);
//            return true;
//        } catch (Exception e) {
//            return false;
//        }
//    }

    public static boolean isEmail(String email) {
        try {
            String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            return matcher.matches();
        } catch (Throwable e) {
            Logs.error("email check", e);
            return false;
        }
    }

    public static boolean phone(String mobiles) {
        try {
            Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
            Matcher m = p.matcher(mobiles);
            return m.matches();
        } catch (Throwable e) {
            Logs.error("phone check", e);
            return false;
        }
    }
}
